/**
 * mikrokosmos ajax
 */

var request = false;
if(!an) var an = navigator.appName;
if(!md) var md = document;

var htmlObj = null;

function set_item_to_populate(itemName){
	htmlObj = md.getElementById(itemName);
}

/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try {
  request = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   request = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   request = false;
  }
 }
@end @*/

if (!request && typeof XMLHttpRequest!='undefined') {
	request = new XMLHttpRequest();
}


/**
 *
 */
function do_ajax_command(params){

	request.open("post", "support/responder.php");
	request.onreadystatechange = onLoad;
	request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	var p = "";
	for(var i in params){
		p += i +"=" +params[i] + "&";
	}
	request.send(p);
}

/**
 * asyncronous server response
 */
function onLoad(){

	//if(htmlObj == null) return false;

	if(request.readyState == 4){
		var response = request.responseXML.documentElement;
		toggle_progressbar(20);
		//alert("hi");

		var node = response.getElementsByTagName("act");
		var n = node[0]
		var actType = n.getAttribute("type");
		//alert(actType);

		do_controller(actType, response);
	}
}

/**
 * switch action
 */
function do_controller(actType, response){

	if(String(actType) == "flasmResponse"){

		var flasmNode = response.getElementsByTagName("flasmCode");
		var msg = "error parsing swf :(";
		if(flasmNode.length){

			var n = flasmNode[0];
			if(n != null) msg = n.firstChild.nodeValue;

			htmlObj = md.getElementById("flasmcode");
			htmlObj.innerHTML = "<pre>" +msg +"</pre>";
		}

		var swfNode = response.getElementsByTagName("swfBox");

		if(swfNode.length){

			var n = swfNode[0];
			msg = "no swf to show";

			if(n  != null) msg = n.firstChild.nodeValue;

			var swfObj = md.getElementById("blankdiv");
			var swfHtml = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" align=\"center\" height=\"100%\">";
    		swfHtml += "\n<tr><td>";
			swfHtml += msg;
			swfHtml += "</td></tr></table>";
			//alert(msg);
			swfObj.innerHTML = swfHtml;
		}
	}
}

